//
//  loanCreatModleFucation.m
//
//
//  Created by gynjobs on 2017/8/11.
//  Copyright © 2017年 gynjobs. All rights reserved.
//

#import "loanCreatModleFucation.h"

@implementation loanCreatModleFucation

+(NSMutableArray *)dataArrayForLoan{
    
    NSMutableDictionary *jsonDic = [[GetJsonData standardGetInstance] getJsonBaseData:@"base" withKey:@"data"];
    
    
    
    NSArray *CellData = @[@[@{@"title":@"职业身份",@"holdPlace":@"请选择职业身份",@"type":@1,@"right":@"arrow_right"}],@[@{@"title":@"贷款金额",@"holdPlace":@"请输入贷款金额",@"type":@2,@"right":@"元"},@{@"title":@"贷款期限",@"holdPlace":@"请选择贷款期限",@"type":@1,@"right":@"arrow_right"},@{@"title":@"贷款用途",@"holdPlace":@"请选择用途",@"type":@1,@"right":@"arrow_right"}],@[@{@"title":@"姓名",@"holdPlace":@"请输入姓名",@"type":@4,@"right":@""},@{@"title":@"工作所在地",@"holdPlace":@"请选择工作所在地",@"type":@1,@"right":@"arrow_right"},@{@"title":@"手机号码",@"holdPlace":@"请输入手机号码",@"type":@4,@"right":@""},@{@"title":@"验证码",@"holdPlace":@"请输入验证码",@"type":@3,@"right":@"获取验证码"}]];
    NSMutableArray *sectionArray = [NSMutableArray array];
    
    for (int i=0; i<CellData.count; i++) {
        NSMutableArray *rowDataArray = [NSMutableArray array];
        NSArray *dataArray = CellData[i];
        for (int j=0; j<dataArray.count;j++) {
            NSMutableDictionary *contenDic = dataArray[j];
            if ([[contenDic objectForKey:@"type"]integerValue]==1) {
                loanTableCellModle *cell1Modle =  [self getNomalCell:[contenDic objectForKey:@"title"] center:[contenDic objectForKey:@"holdPlace"]];
                [rowDataArray addObject:cell1Modle];
            }else if ([[contenDic objectForKey:@"type"]integerValue]==2){
                loanTableCellModle *cell2Modle =  [self getRightLableCell:[contenDic objectForKey:@"title"] center:[contenDic objectForKey:@"holdPlace"] rightString:[contenDic objectForKey:@"right"]];
                [rowDataArray addObject:cell2Modle];
            }else if ([[contenDic objectForKey:@"type"]integerValue]==3){
                loanTableCellModle *cell3Modle =  [self getRightButtonCell:[contenDic objectForKey:@"title"] center:[contenDic objectForKey:@"holdPlace"]];
                [rowDataArray addObject:cell3Modle];
            }else{
                loanTableCellModle *cell4Modle =  [self getNoneRightCell:[contenDic objectForKey:@"title"] center:[contenDic objectForKey:@"holdPlace"]];
                [rowDataArray addObject:cell4Modle];
            }
        }
        [sectionArray addObject:rowDataArray];
    }
    return sectionArray;
}


+(loanTableCellModle *)getNomalCell:(NSString *)title center:(NSString *)holdString{
    return [self creatAccessCellWiht:title centerHoldPlace:holdString cellType:1 andRight:@"arrow_right"];
}
+(loanTableCellModle *)getRightLableCell:(NSString *)title center:(NSString *)holdString rightString:(NSString *)rightString{
    return [self creatAccessCellWiht:title centerHoldPlace:holdString cellType:2 andRight:@"元"];
}
+(loanTableCellModle *)getRightButtonCell:(NSString *)title center:(NSString *)holdString{
    return [self creatAccessCellWiht:title centerHoldPlace:holdString cellType:3 andRight:@"获取验证码"];
}
+(loanTableCellModle *)getNoneRightCell:(NSString *)title center:(NSString *)holdString{
    return [self creatAccessCellWiht:title centerHoldPlace:holdString cellType:4 andRight:@""];
}

+(loanTableCellModle *)creatAccessCellWiht:(NSString *)titleString centerHoldPlace:(NSString *)holdString
                                  cellType:(NSInteger)index andRight:(NSString *)rightSting{
    loanTableCellModle *molde = [[loanTableCellModle alloc]init];
    molde.holdPlaceString = holdString;
    molde.cellType = selectCellAcc;
    molde.titleString = titleString;
    switch (index) {
        case 1:
        {
            [self SetTypeAndRightImage:molde andImage:rightSting];
            molde.cellType = selectCellAcc;
        }
            break;
        case 2:
        {
            [self SetTypeAndRightLable:molde andLable:rightSting];
            molde.cellType = inputCellLable;
        }
            break;
        case 3:
        {
            [self SetTypeAndRightButton:molde andButton:rightSting];
            molde.cellType = buttonCell;
        }
            break;
            
        default:{
            molde.cellType = inputCellNone;
            molde.rightSize = CGSizeMake(0, 0);
        }
            break;
    }
    return molde;
}
+(void)SetTypeAndRightImage:(loanTableCellModle *)mold andImage:(NSString *)imageString{
    UIImageView *testimage = [[UIImageView alloc]init];
    testimage.backgroundColor = [UIColor clearColor];
    testimage.image = [UIImage imageNamed:imageString];
    testimage.contentMode = UIViewContentModeCenter;
    mold.rightSize = CGSizeMake(6, 11);
    mold.subViewOfRightView = testimage;
}
+(void)SetTypeAndRightButton:(loanTableCellModle *)mold andButton:(NSString *)buttonTitle{
    UIButton *testButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [testButton setBackgroundColor:[UIColor clearColor]];
    [testButton setTitle:buttonTitle forState:UIControlStateNormal];
    [testButton setTitleColor:NavBarColor forState:UIControlStateNormal];
    [testButton sizeToFit];
    mold.rightSize = CGSizeMake(testButton.frame.size.width, 0);
    //设置位置
    mold.subViewOfRightView = testButton;
}
+(void)SetTypeAndRightLable:(loanTableCellModle *)mold andLable:(NSString *)lableString{
    UILabel *testLabel = [[UILabel alloc]init];
    testLabel.backgroundColor = [UIColor clearColor];
    testLabel.text = lableString;
    [testLabel sizeToFit];
    mold.rightSize = testLabel.frame.size;
    mold.subViewOfRightView = testLabel;
    
}
@end
